VFG.DrawPPoint=function(viewer,option){
	this.viewer=viewer;
	this.option=option;
	this.tip=new VFG.Tip(viewer);
	this.init();
}

VFG.DrawPPoint.prototype.init = function() {
	var _this=this;
	this.handler = new Cesium.ScreenSpaceEventHandler(this.viewer.scene.canvas);
	this.handler.setInputAction(function (movement) {
		let position=VFG.Util.getScreenToLnLa(_this.viewer, movement.position, null);
    	if (Cesium.defined(position)){
    		let entity=_this.render(position);
    		if(entity && _this.success){
    			_this.success(entity);
    		}
    	}
    },Cesium.ScreenSpaceEventType.LEFT_CLICK)
    
    this.handler.setInputAction(function (movement) {
    	_this.tip.showAt(movement.endPosition,"单击添加标注，右键取消！");
    }, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
	this.handler.setInputAction(function (movement) {
		_this.destroy();
	}, Cesium.ScreenSpaceEventType.RIGHT_CLICK);
};

VFG.DrawPPoint.prototype.render = function(position) {
	var _this=this;
	if (Cesium.defined(position)){
		this.option.id=VFG.Util.getUuid();
		this.option.position=position;
		return new VFG.PPoint(_this.viewer,this.option);
	}
};

VFG.DrawPPoint.prototype.on=function(type,callback){
	if('success'==type){
		this.success=callback;
	}
	if('error'==type){
		this.error=callback;
	}
}


VFG.DrawPPoint.prototype.destroy = function() {
	if(this.complete){
		this.complete();
	}
    if( this.handler){
    	this.handler.destroy();
    	this.handler = null;
    };
    if(this.tip){
    	this.tip.destroy();
    }
	delete this.option;
    delete this.viewer;
	return Cesium.destroyObject(this);
};
